package com.wjh.graduation.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * Created on 2022/1/23.
 *
 * @author Wu Jiahong
 */
@Slf4j
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {
	/**
	 * 文档参数配置
	 */
	@Value("${swagger.title}")
	public String title;
	@Value("${swagger.description}")
	public String description;
	@Value("${swagger.version}")
	public String version;
	@Value("${swagger.contactName}")
	public String contactName;
	@Value("${swagger.contactUrl}")
	public String contactUrl;
	@Value("${swagger.contactEmail}")
	public String contactEmail;

	@Bean(value = "knife4jApi")
	public Docket defaultApi2() {
		log.info("swagger is configured!");
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(new ApiInfoBuilder()
						.title(title)
						.description(description)
						.termsOfServiceUrl(contactUrl)
						.contact(new Contact(contactName, contactUrl, contactEmail))
						.version(version)
						.build())
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.wjh.graduation"))
				.paths(PathSelectors.any())
				.build();
	}
}
